package DataLayer;

import java.sql.ResultSet;
import java.sql.SQLException;
import Domain.Besked;
import Domain.Bruger;
import Domain.Lokation;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class Mapper {
	
	private ResultSet rs;
	private Statement stmt;
	
	public Mapper() {
		
	}
	
	public void opretBruger(Bruger bruger, Connection con) {
		
		try {
			Statement stmt = (Statement) con.createStatement();
			String query = "INSERT INTO adm_brugere (email, password, rights, firstname, lastname, newuser, logins) VALUES ('" + bruger.getEmail() + "','" + bruger.getPassword() + "'," + bruger.getRights() + ",'" + bruger.getFirstname() + "','" + bruger.getLastname() + "', 1, 1);";
			System.out.println(query);
			stmt.executeUpdate(query);
			stmt.close();
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	public void opretBesked(Besked besked, Connection con) {
		
		try {
			Statement stmt = (Statement) con.createStatement();
			String query = "INSERT INTO adm_beskeder (subject, message, user, timestamp) VALUES ('" + besked.getEmne() + "','" + besked.getBesked() + "'," + besked.getBruger() + "," + besked.getTimeStampString() + ");";
			System.out.println(query);
			stmt.executeUpdate(query);
			stmt.close();
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	public void opretLokation(Lokation lokation, Connection con) {
		
		try {
			Statement stmt = (Statement) con.createStatement();
			String query = "INSERT INTO adm_lokationer (name, floor, zipcode) VALUES ('" + lokation.getNavn() + "','" + lokation.getEtage() + "'," + lokation.getPostnummer() + ");";
			System.out.println(query);
			stmt.executeUpdate(query);
			stmt.close();
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

}
